using System.Collections.Generic;
using NodeCanvas.Framework;
using ParadoxNotion.Design;
using UnityEngine;

namespace Yoozoo.Gameplay.Liberty.AI.Node
{
    [Category("Ggame/Liberty")]
    public class NpcShouldSwitchTarget : AIConditionBaseNode
    {
        // 血量降到多少以下切换目标
        public BBParameter<int> switchHealth = 70;
        // 随机切换目标的概率
        public BBParameter<float> probability = 1f;

        protected override string info {
            get { return $"npc healthPoint<={switchHealth.value} \nor probability<={probability.value}\n then should switch target"; }
        }
        
        protected override bool OnCheck()
        {
            BattleAgent battleAgent = _entity.battleAgent;
            // 可能的目标
            AIEntity possibleTarget = battleAgent.revengeTarget;
            // 当前锁定的目标
            AIEntity currentTarget = battleAgent.currentLockTarget;
            
            if (possibleTarget==null || currentTarget==possibleTarget)
            {
                return false;
            }

            bool switchTarget = false;
            if (currentTarget == null)
            {
                switchTarget = true;
            }
            else if (!battleAgent.ignoreTargets.Contains(possibleTarget))
            {
                if(currentTarget.data.hp > switchHealth.value || Random.Range(0f, 1f) > probability.value)
                {
                    switchTarget = true;
                }
            }

            return switchTarget;
        }
    }
}